function identity<T>(arg: T) {
    return arg;
}

{
//let abc: string 
let a = identity<string>("你好");
let abd = identity<number>(1);
}

/**
 * 传多个泛型
 * @param data1 
 * @param data2 
 */
function identity2<T, U>(data1: T, data2: U) {
    Date.now() % 2 ? console.log(data1) : console.log(data2)
}

identity2<string, number>('sss', 111)
identity2<number, boolean>(111, true)

/**
 * 泛型返回值
 * @param data1 
 * @param data2 
 * @returns T | U
 */
function identity3<T, U>(data1: T, data2: U): T | U {
    return Date.now() % 2 ? data1 : data2
}
console.log(identity3<string, number>('sss', 111))

/**
 * 
 * @param arg 泛型数组
 * @returns 
 */
function loggingIdentity<T>(arg: T[]): T[] {
    console.log(arg.length);
    return arg;
}

loggingIdentity([1, 2])
loggingIdentity<number>([1, 2])

/**
 * 泛型在接口使用
 */
interface PersonTer<T> {
    name: string,
    age: number,
    extraInfo: T
}

type JobInfo = {
    title: string;
    company: string;
}

let p0: PersonTer<number> = {
    name: 'jack',
    age: 12,
    extraInfo: 250 // 传number
}

// T传type类型
let p10: PersonTer<JobInfo> = {
    name: 'jack',
    age: 12,
    extraInfo: {
        title: "",
        company: "cc"
    }
}
